/**
 * 个人中心界面
 */
class userSub extends eui.Component{
    private return:eui.Button;
    private head:eui.Image;
    private maskBg:eui.Rect;
    private lv:eui.Label;
    private title:eui.Label;
    private userId:eui.Label;
    private exp:eui.Label;
    private project:eui.Rect;
    private ruleBtn:eui.Button;
    private nickName:eui.Label;
    private sex:eui.Label;
    private birth:eui.Label;
    private phone:eui.Label;
    private editName:eui.Image;
    private editSex:eui.Image;
    private editBirth:eui.Image;
    private editPhone:eui.Image;
    private finish:eui.Image;

    private _rulePage:ruleSub;
    public constructor(){
        super();
        this.addEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent,this);
        this.skinName = "userSkin"; 
    }

    private createCompleteEvent():void{
        this.removeEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent, this);
        this.inIt();
    }

    private inIt(){
        this.head.mask = this.maskBg;
        this.return.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{
            this.dispatchEventWith("return");
        },this);
        this.ruleBtn.addEventListener( egret.TouchEvent.TOUCH_TAP, this.mbtnHandler, this );
        this.editName.addEventListener( egret.TouchEvent.TOUCH_TAP, this.mbtnHandler, this );
        this.editSex.addEventListener( egret.TouchEvent.TOUCH_TAP, this.mbtnHandler, this );
        this.editBirth.addEventListener( egret.TouchEvent.TOUCH_TAP, this.mbtnHandler, this );
        this.editPhone.addEventListener( egret.TouchEvent.TOUCH_TAP, this.mbtnHandler, this );
        this.finish.addEventListener( egret.TouchEvent.TOUCH_TAP, this.mbtnHandler, this );
        this.assignValue();
    }
    private mbtnHandler(evt:egret.TouchEvent){
        let btn = evt.currentTarget;
        switch(btn){
            case this.ruleBtn:{
                if(!this._rulePage){
                    this._rulePage = new ruleSub();
                }
                this.addChild(this._rulePage);
                break;
            }
            case this.editName:{
                
                break;
            }
            case this.editSex:{
                
                break;
            }
            case this.editBirth:{
                
                break;
            }
            case this.editPhone:{

                break;
            }
            case this.finish:{
                
                break;
            }
        }
        if(btn !== this.ruleBtn){
            let toast:Toast = new Toast();
            toast.show("修改功能暂未开放，敬请期待哦");
            this.addChild(toast);
        }
    }
    private assignValue():void{
        this.head.source = common.userInfo.head;
        this.lv.text = "lv" + common.userInfo.lv;
        this.title.text = common.userInfo.title;
        this.userId.text = "用户ID: " + common.userInfo.userId;
        this.exp.text = common.userInfo.exp + "/" + common.userInfo.maxExp;
        this.project.width = 242 * (common.userInfo.exp / common.userInfo.maxExp);
        this.nickName.text = common.userInfo.nickName;
        this.sex.text = common.userInfo.sex == 2 ? "女" : "男";
        this.birth.text = "";
        this.phone.text = "";
    }
    public resetExp(){
        this.exp.text = common.userInfo.exp + "/" + common.userInfo.maxExp;
        this.project.width = 242 * (common.userInfo.exp / common.userInfo.maxExp);
    }
}

class ruleSub extends eui.Component{
    private return:eui.Image;
    public constructor(){
        super();
        this.addEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent,this);
        this.skinName = "ruleSkin"; 
    }

    private createCompleteEvent():void{
        this.removeEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent, this);
        this.return.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{
            this.parent.removeChild(this);
        },this);
    }
}